//
// Created by hoyin on 2022/2/8.
//

#ifndef AUST_RM_VISION_2022_SINGLETRACK_H
#define AUST_RM_VISION_2022_SINGLETRACK_H

#include <opencv2/opencv.hpp>
#include <opencv2/tracking.hpp>
#include <opencv2/core/ocl.hpp>
#include "MVCamera.h"
#include "Matcher.h"

using namespace cv;
using namespace std;
using namespace mvc;


namespace st {
	const struct TrackerType {
		static const short BOOSTING = 0;
		static const short MIL = 1;
		static const short KCF = 2;
		static const short TLD = 3;
		static const short MEDIANFLOW = 4;
		static const short MOSSE = 5;
		static const short CSRT = 6;
	} TrackerType;

	const struct SourceType {
		static const short VIDEO = 0;
		static const short UVC_CAMERA = 1;
		static const short HIKVISION_MV_CAMERA = 2;
	} SourceType;

	const string trackerTypes[7] = { "BOOSTING", "MIL", "KCF", "TLD","MEDIANFLOW", "MOSSE", "CSRT" };

	class SingleTrack {
	private:
		Ptr<Tracker> tracker;
		int trackerType = -1;
		int frameWidth{}, frameHeight{};
		VideoCapture video;
		MVCamera *camera;
		int sourceType{};
		bool cudaSupport{};
		Mat trackingTarget;
		Matcher matcher;
	public:
		void initTracker();
		SingleTrack(int trackerType, const VideoCapture& video, int frameWidth, int frameHeight, bool cudaSupport);
		SingleTrack(int trackerType, MVCamera *mvCamera, int frameWidth, int frameHeight, bool cudaSupport);
		SingleTrack();
		int startTracking(Rect2d bbox, int startFrame, Mat *trackResult, bool displayStream = true);
		Rect2d selectTrackingBox(int indexOfFrame = 0, const Rect2d& defaultBox = Rect2d());
		bool readFrame(Mat& frame);
	};
}

#endif //AUST_RM_VISION_2022_SINGLETRACK_H
